#include "stdafx.h"

#include "qrebar.h"


using namespace micro::gui;

// standard rebar styles - alex
#define SIMPLE_REBAR_STYLE \
	(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER  | CCS_ADJUSTABLE)

// rebar without borders 
#define SIMPLE_REBAR_NOBORDER_STYLE \
	(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | RBS_VARHEIGHT | RBS_BANDBORDERS | RBS_AUTOSIZE | CCS_NODIVIDER)
 
// standard command bar styles
#define SIMPLE_CMDBAR_PANE_STYLE \
	(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER | CCS_NORESIZE | CCS_NOPARENTALIGN)

	
QReBar::QReBar(void)
{
 
}

QReBar::~QReBar(void)
{
}

bool QReBar::Create(QWindow* parent,int id, UINT style)
{

	bool bo = CreateBaseWindowEx(
		WS_EX_TOOLWINDOW,
		REBARCLASSNAME, nullptr,  
		SIMPLE_REBAR_STYLE      
		,QRect(0,0,0,0), parent, 0, 0, 0);

 
	if (!bo) return false;

	REBARINFO rbi;
	rbi.cbSize = sizeof(REBARINFO);  // Required when using this struct.
	rbi.fMask = 0;
	rbi.himl = (HIMAGELIST)nullptr;

	SetBarInfo(&rbi);
	return bo;  
}



bool QReBar::AddBand(QToolBar &toolBar,int iID, UINT style)
{
	QSize size;
	toolBar.GetMaxSize(&size);

	QRect rect =  toolBar.GetWindowRect();
	REBARBANDINFO rbBand=	{0};
	rbBand.cbSize		=	sizeof(REBARBANDINFO);    // Required
	rbBand.fMask		=	RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE |RBBIM_ID ;//|RBBIM_IDEALSIZE;
	rbBand.fStyle		=	style;//|RBBS_GRIPPERALWAYS ;	 
	rbBand.clrFore		=	0;
	rbBand.clrBack		=	0;
	rbBand.lpText		=	0;
	rbBand.cch			=	0;
	rbBand.iImage		=	0;
	rbBand.hwndChild	=	toolBar.GetHandle();
	rbBand.cxMinChild	=	size.cx;
	rbBand.cyMinChild	=	size.cy;;
	rbBand.cx			=	0;
	rbBand.hbmBack		=	0;
	rbBand.wID			=	iID;
    rbBand.cyChild		=	size.cy;
    rbBand.cyMaxChild	=	size.cy;
    rbBand.cyIntegral	=	0;
    rbBand.cxIdeal		=	size.cx;
    rbBand.lParam		=	0;
    rbBand.cxHeader		=	0;


    
  
  
	bool bo =  InsertBand(-1, &rbBand);
	//return bo;

	if ( style & RBBS_USECHEVRON )
	{
		
 
		// This will be the band we just added
		UINT iBandIndex = GetBandCount( )-1;
		// BUGBUG:
		// CToolBarCtrl::GetMaxSize( ) doest seem to return proper size when
		// TBSTYLE_DROPDOWN style is set for buttons.. Anybody knows any way ?

		
		
		// Set band prop
		REBARBANDINFO rbbi;
		rbbi.cbSize = sizeof(rbbi);
		rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE ;
		rbbi.cxMinChild = 0;
		rbbi.cyMinChild = size.cy;
		rbbi.cx = size.cx;
		rbbi.cxIdeal = size.cx;

		SetBandInfo( iBandIndex, &rbbi); 
	}


	//DWORD dwExStyle = (DWORD)::SendMessage(toolBar, TB_GETEXTENDEDSTYLE, 0, 0L);
	//::SendMessage(toolBar, TB_SETEXTENDEDSTYLE, 0, dwExStyle | TBSTYLE_EX_HIDECLIPPEDBUTTONS);


	return bo;
}


bool QReBar::OnSize(int type, int cx,int cy)
{
	return true;

}